*******************************************************************************
*   REPLICATION MATERIAL FOR                                                  *
*                                                                             *
*   INDIVIDUAL LIFE HORIZON INFLUENCES ATTITUDES TOWARD DEMOCRACY             *
*                                                                             *
*   BY                                                                        *
*                                                                             *
*   MARIE LECHLER AND UWE SUNDE                                               *
*                                                                             *
*   AMERICAN POLITICAL SCIENCE REVIEW                                         *
*                                                                             *
*******************************************************************************


***** Overview Results *****
*****************************

set scheme s1color
set matsize 1500
graph set window fontface "CMR Sans Serif"


use LS_replication_data.dta, clear

replace having_democ=5-having_democ
g intlifeexp = int(life_exp)
reg having_democ  ib40.intlifeexp i.sex ib40.age i.country1 i.period , vce(cluster treatment_groups2)
gen sample=0
replace sample=1 if e(sample)==1


********************************************************************************
* FIGURE 2
********************************************************************************


* Semi-parametric estimation

gen counter=_n if _n>0 & _n<=100

gen beta_ry_all =.
gen se_ry_all_lo = .
gen se_ry_all_hi = .
gen beta_age_all=.
gen se_age_all_lo = .
gen se_age_all_hi = .
gen beta_age_all_male=.
gen se_age_all_lo_male=.
gen se_age_all_hi_male=.

gen beta_ry_fe  =. 
gen se_ry_fe_lo =. 
gen se_ry_fe_hi =. 
gen beta_age_fe =. 
gen se_age_fe_lo =. 
gen se_age_fe_hi =. 



** Specification 1a (Baseline)

reg having_democ  ib40.intlifeexp  i.sex ib40.age  i.country1 i.period , vce(cluster treatment_groups)

* Effect of remaining years of life dummies

forvalues counter=2/67 {
replace beta_ry_fe=_b[`counter'.intlifeexp] if _n==`counter' & _b[`counter'.intlifeexp] !=.
replace se_ry_fe_lo=_b[`counter'.intlifeexp]-_se[`counter'.intlifeexp]*1.96 if _n==`counter'
replace se_ry_fe_hi=_b[`counter'.intlifeexp]+_se[`counter'.intlifeexp]*1.96 if _n==`counter'
}

* Age-effect 
forvalues counter=16/95 {
replace beta_age_fe=_b[`counter'.age] if _n==`counter'
replace se_age_fe_lo=_b[`counter'.age]-_se[`counter'.age]*1.96 if _n==`counter'
replace se_age_fe_hi=_b[`counter'.age]+_se[`counter'.age]*1.96 if _n==`counter'
}



** Specification 1b (Extended)

reg having_democ  ib40.intlifeexp ib40.age i.sex i.sex#i.age  i.country1##i.period, vce(cluster treatment_groups2)

* Effect of remaining years of life dummies

forvalues counter=1/68 {
replace beta_ry_all=_b[`counter'.intlifeexp] if _n==`counter' & _b[`counter'.intlifeexp] !=.
replace se_ry_all_lo=_b[`counter'.intlifeexp]-_se[`counter'.intlifeexp]*1.96 if _n==`counter'
replace se_ry_all_hi=_b[`counter'.intlifeexp]+_se[`counter'.intlifeexp]*1.96 if _n==`counter'
}

* Age-effect Female (sex=0)

forvalues counter=15/97 {
replace beta_age_all=_b[`counter'.age] if _n==`counter'
replace se_age_all_lo=_b[`counter'.age]-_se[`counter'.age]*1.96 if _n==`counter'
replace se_age_all_hi=_b[`counter'.age]+_se[`counter'.age]*1.96 if _n==`counter'
}


* Age-effect Male new (sex=1)

forvalues counter=15/97 {
lincom `counter'.age  + 1.sex#`counter'.age
replace beta_age_all_male= r(estimate) if _n==`counter'
replace se_age_all_lo_male= r(estimate)- r(se)*1.96 if _n==`counter'
replace se_age_all_hi_male= r(estimate)+ r(se)*1.96 if _n==`counter'
}


twoway  (rarea se_ry_fe_lo se_ry_fe_hi counter if counter<70, color(gs14)) (rarea se_ry_all_lo se_ry_all_hi counter if counter<70 & counter>2, color(gs14))  (line beta_ry_fe counter if counter<70 & counter>2,  lcolor(black))   (line beta_ry_all counter if counter<70 & counter>2, lpattern(dash) lcolor(black))  , graphregion(color(white)) legend(order (3 1 4 2) label(1 "95% C.I.") label(2 "95% C.I.") label(4 "Extended Specification") label(3 "Baseline Specification")) xtitle(Remaining Life Years) ytitle(Attitude towards Democracy)   yline(0)
graph export "Figure_2a.pdf", replace

twoway (rarea se_age_all_lo_male se_age_all_hi_male counter if counter>13&counter<89, color(gs14)) (rarea se_age_fe_lo se_age_fe_hi counter if counter>13&counter<89, color(gs14)) (rarea se_age_all_lo se_age_all_hi counter if counter>13&counter<89, color(gs14))    (line beta_age_fe counter if counter>13&counter<89,  lcolor(black))   (line beta_age_all counter if counter>13&counter<89, lpattern(dot) lcolor(black)) (line beta_age_all_male counter if counter>13&counter<89, lpattern(_.) lcolor(black)) , graphregion(color(white)) legend(rows(3) order(4 1 5 2 6 3) label(1 "95% C.I.") label(2 "95% C.I.") label(3 "95% C.I.") label(4 "Baseline Specification") label(5 "Extended Specification: Females") label(6 "Extended Specification: Males")) xtitle(Age) ytitle(Attitude towards Democracy)   yline(0)
graph export "Figure_2b.pdf", replace




********************************************************************************
* TABLE 1
********************************************************************************


reg having_democ  life_exp life_exp2 i.sex i.age i.country1 i.period , vce(cluster treatment_groups2)
est store reg1
estadd scalar Cluster = e(N_clust)
estadd local CountryFE "$\checkmark$" , replace
estadd local AgegroupFE "$\checkmark$" , replace
estadd local GenderFE "$\checkmark$" , replace
estadd local SurveyroundFE "$\checkmark$" , replace
estadd local Country_round_FE "" , replace
estadd local age_gender_FE "" , replace
estadd local children "" , replace
estadd local trust "" , replace
estadd local education "" , replace
estadd local marital_status "" , replace
estadd local income "" , replace
estadd local health "" , replace

reg having_democ  life_exp life_exp2 i.sex i.age i.country1 i.period if age<=60, vce(cluster treatment_groups2)
est store reg2
estadd scalar Cluster = e(N_clust)
estadd local CountryFE "$\checkmark$" , replace
estadd local AgegroupFE "$\checkmark$" , replace
estadd local GenderFE "$\checkmark$" , replace
estadd local SurveyroundFE "$\checkmark$" , replace
estadd local Country_round_FE "" , replace
estadd local age_gender_FE "" , replace
estadd local children "" , replace
estadd local trust "" , replace
estadd local education "" , replace
estadd local marital_status "" , replace
estadd local income "" , replace
estadd local health "" , replace

reg having_democ  life_exp life_exp2 i.sex i.age i.country1##i.period , vce(cluster treatment_groups2)
est store reg3
estadd scalar Cluster = e(N_clust)
estadd local CountryFE "$\checkmark$" , replace
estadd local AgegroupFE "$\checkmark$" , replace
estadd local GenderFE "$\checkmark$" , replace
estadd local SurveyroundFE "$\checkmark$" , replace
estadd local Country_round_FE "$\checkmark$" , replace
estadd local age_gender_FE "" , replace
estadd local children "" , replace
estadd local trust "" , replace
estadd local education "" , replace
estadd local marital_status "" , replace
estadd local income "" , replace
estadd local health "" , replace


reg having_democ  life_exp life_exp2 i.sex##i.age i.country1 i.period , vce(cluster treatment_groups2)
est store reg4
estadd scalar Cluster = e(N_clust)
estadd local CountryFE "$\checkmark$" , replace
estadd local AgegroupFE "$\checkmark$" , replace
estadd local GenderFE "$\checkmark$" , replace
estadd local SurveyroundFE "$\checkmark$" , replace
estadd local Country_round_FE "" , replace
estadd local age_gender_FE "$\checkmark$" , replace
estadd local children "" , replace
estadd local trust "" , replace
estadd local education "" , replace
estadd local marital_status "" , replace
estadd local income "" , replace
estadd local health "" , replace

reg having_democ  life_exp life_exp2 i.sex##i.age i.country1##i.period , vce(cluster treatment_groups2)
est store reg5r
estadd scalar Cluster = e(N_clust)
estadd local CountryFE "$\checkmark$" , replace
estadd local AgegroupFE "$\checkmark$" , replace
estadd local GenderFE "$\checkmark$" , replace
estadd local SurveyroundFE "$\checkmark$" , replace
estadd local Country_round_FE "$\checkmark$" , replace
estadd local age_gender_FE "$\checkmark$" , replace
estadd local children "" , replace
estadd local trust "" , replace
estadd local education "" , replace
estadd local marital_status "" , replace
estadd local income "" , replace
estadd local health "" , replace


reg having_democ  life_exp life_exp2 democcapitalPolIVbyage children_bin trust_bin i.education i.income i.marital_status health i.sex i.age i.country1 i.period , vce(cluster treatment_groups2)
est store reg5
estadd scalar Cluster = e(N_clust)
estadd local CountryFE "$\checkmark$" , replace
estadd local AgegroupFE "$\checkmark$" , replace
estadd local GenderFE "$\checkmark$" , replace
estadd local SurveyroundFE "$\checkmark$" , replace
estadd local Country_round_FE "" , replace
estadd local age_gender_FE "" , replace
estadd local children "$\checkmark$" , replace
estadd local trust "$\checkmark$" , replace
estadd local education "$\checkmark$" , replace
estadd local marital_status "$\checkmark$" , replace
estadd local income "$\checkmark$" , replace
estadd local health "$\checkmark$" , replace

reg having_democ  life_exp life_exp2 democcapitalPolIVbyage children_bin trust_bin i.education i.income i.marital_status health i.sex##i.age i.country1##i.period , vce(cluster treatment_groups2)
est store reg6
estadd scalar Cluster = e(N_clust)
estadd local CountryFE "$\checkmark$" , replace
estadd local AgegroupFE "$\checkmark$" , replace
estadd local GenderFE "$\checkmark$" , replace
estadd local SurveyroundFE "$\checkmark$" , replace
estadd local Country_round_FE "$\checkmark$" , replace
estadd local age_gender_FE "$\checkmark$" , replace
estadd local children "$\checkmark$" , replace
estadd local trust "$\checkmark$" , replace
estadd local education "$\checkmark$" , replace
estadd local marital_status "$\checkmark$" , replace
estadd local income "$\checkmark$" , replace
estadd local health "$\checkmark$" , replace

label variable democcapitalPolIVbyage "Democratic~Capital"
label variable life_exp2 "Remaining Years\textsuperscript{2}" 
label variable life_exp "Remaining~Years" 

esttab reg1 reg2 reg3 reg4 reg5r reg6 using "Table1.tex", replace booktabs ///
mtitles("Full" "Age$<$60" "Full"  "Full" "Full" "Full") ///
label keep(life_exp life_exp2 democcapitalPolIVbyage)    ///
s(CountryFE  SurveyroundFE  AgegroupFE GenderFE Country_round_FE age_gender_FE children marital_status trust education income health r2 N Cluster,  fmt(%16s %16s %16s %16s %16s %16s %16s %16s %16s %16s %16s %16s  %12.2fc  %12.0fc %12.0fc) label("Country FE" "Survey round FE" "Age FE" "Gender FE" "Country x Survey round FE" "Age x Gender FE" "Children" "Marital Status" "Trust" "Education Dummies" "Income Dummies" "Subj. Health" "R\textsuperscript{2}" "N" "Cluster")) nonotes se(%12.4fc) 
